﻿'******************************************************
'******************************************************
'Application Title: Google Widget Editor
'version: 1.0
'Date: 01-02-2008
'Requirements: win2k or later
'Author: Andrew Pye
'Author Email: StretchMasterP@googlemail.com
'License: Released under GNU GENERAL PUBLIC LICENSE v3
'ToDo:
'Changes:Imports System.Text
'******************************************************
'******************************************************

Imports System.ComponentModel
Imports System.Text
''' <summary>
''' class to handle requirments
''' </summary>
''' <remarks></remarks>
Public Class Require
    Implements IObjectName

    '<Require feature="opensocial-0.8"/>
#Region "Fields"
    Private _feature As String = String.Empty
    Private _Optional As Boolean = False
    Private _Parent As RequireLibs = Nothing
#End Region
#Region "Constructor"
    Public Sub New()
    End Sub
    Public Sub New(ByVal feature As String)
        Me.Feature = feature
    End Sub
    Public Sub New(ByVal feature As String, ByVal [Optional] As Boolean)
        Me.Feature = feature
        Me.Optional = [Optional]
    End Sub
#End Region
#Region "Property"
    Protected ReadOnly Property Parent() As Object Implements IObjectName.Parent
        Get
            Return _Parent
        End Get
    End Property
    Public Sub SetParent(ByVal ParentObject As Object) Implements IObjectName.SetParent
        _Parent = ParentObject
    End Sub
    <TypeConverter(GetType(RequireList)), _
    CategoryAttribute("Misc"), DefaultValueAttribute(""), _
    DescriptionAttribute("Select a state from the list")> _
    Public Property Feature() As String
        Get
            Return _feature
        End Get
        Set(ByVal value As String)
            _feature = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Misc"), DescriptionAttribute("Is this require lib optional")> _
    Public Property [Optional]() As Boolean
        Get
            Return _Optional
        End Get
        Set(ByVal value As Boolean)
            _Optional = value
            Me.SetDirty()
        End Set
    End Property
    <Browsable(False)> _
    Public ReadOnly Property ObjectName() As String Implements IObjectName.ObjectName
        Get
            Return Me._feature
        End Get
    End Property
#End Region
#Region "Methods"
    Public Function BuildXml() As String
        Dim sb As StringBuilder = New StringBuilder
        If Me.Optional = True Then
            sb.AppendLine("<Require optional feature='" & Me._feature & "'/>")
        Else
            sb.AppendLine("<Require feature='" & Me._feature & "'/>")
        End If
        Return sb.ToString
    End Function
    Public Sub SetDirty()
        If Me.Parent IsNot Nothing Then Me.Parent.SetDirty()
    End Sub
#End Region


End Class
''' <summary>
''' Collection of Requirments
''' </summary>
''' <remarks></remarks>
Public Class RequireLibs
    Inherits ObjectModel.Collection(Of Require)
    Implements IObjectName
#Region "Fields"
    Private _Parent As Widget = Nothing
    Private _IsDirty As Boolean = False
#End Region
#Region "Methods"
    Public Shadows Sub Add(ByVal oRequire As Require)
        MyBase.Add(oRequire)
    End Sub
    Public Shadows Sub Add(ByVal feature As String)
        MyBase.Add(New Require(feature))
    End Sub
    Public Shadows Sub Add(ByVal feature As String, ByVal [Optional] As Boolean)
        MyBase.Add(New Require(feature, [Optional]))
    End Sub
#End Region
#Region "Constructor"
    Public Sub New()

    End Sub
#End Region
#Region "Methods"
    Public Sub SetDirty()
        If Me.Parent IsNot Nothing Then Me.Parent.SetDirty()
    End Sub
    Public Function BuildXml() As String
        Dim sb As StringBuilder = New StringBuilder
        For Each Tobj As Require In Me
            Dim strbuf As String = Tobj.BuildXml
            If Not String.IsNullOrEmpty(strbuf) Then
                sb.AppendLine(Tobj.BuildXml)
            End If
        Next
        Return sb.ToString
    End Function
    Public Function HasReqLib(ByVal Name As String) As Boolean
        For Each o_lib As Require In Me
            If o_lib.Feature.ToUpper = Name.ToUpper Then
                Return True
            End If
        Next
        Return False
    End Function
    Protected Overrides Sub InsertItem(ByVal index As Integer, ByVal item As Require)
        MyBase.InsertItem(index, item)
        item.SetParent(Me)
    End Sub
#End Region
#Region "Properties"
    Public Property IsDirty() As Boolean
        Get
            Return _IsDirty
        End Get
        Set(ByVal value As Boolean)
            _IsDirty = value
        End Set
    End Property
    Protected ReadOnly Property Parent() As Object Implements IObjectName.Parent
        Get
            Return _Parent
        End Get
    End Property
    Public Sub SetParent(ByVal ParentObject As Object) Implements IObjectName.SetParent
        _Parent = ParentObject
    End Sub
    <Browsable(False)> _
    Public ReadOnly Property ObjectName() As String Implements IObjectName.ObjectName
        Get
            Return "RequireLibs"
        End Get
    End Property
#End Region
End Class